package com.sg.service.biz.framework.impl;

import com.sg.common.util.CommonFunctionHelper;
import com.sg.common.util.RedisUtil;
import com.sg.dto.base.framework.req.QueryOrgDetailReq;
import com.sg.dto.biz.framework.req.ObtainCommonFieldRefComReqDto;
import com.sg.dto.biz.framework.req.QueryReceiveFieldDetailReqDto;
import com.sg.dto.biz.framework.req.QuerySpaceManagerDetailComReqDto;
import com.sg.dto.biz.framework.res.ObtainCommonFieldRefComRespDto;
import com.sg.dto.biz.framework.res.QueryReceiveFieldDetailRespDto;
import com.sg.dto.biz.framework.res.QuerySpaceManagerDetailComRespDto;
import com.sg.dto.integration.component.GenerateDataObjectBatchCodeComReqDto;
import com.sg.dto.integration.component.GenerateDataObjectBatchCodeComRespDto;
import com.sg.entity.Organization;
import com.sg.service.base.framework.MOrganizationService;
import com.sg.service.biz.framework.RoleService;
import com.wicket.okrcomponent.integration.InterfaceModeService;
import com.sg.common.exception.Assert;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class DashboradStandardDataServiceImpl
        implements com.wicket.okrframework.biz.service.DashboradStandardDataService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private MOrganizationService mOrganizationService;
    @Resource
    private RoleService roleService;
    //@Resource
    //private MCustomFields2Service mCustomFields2Service;
    @Resource
    private NbDashboradStandardData nbDashboradStandardData;
    @Resource
    private InterfaceModeService interfaceModeService;

    /**
     * D1获取公共字段入参(公共)[8943]
     * gen by moon at 5/21/2024, 2:02:32 AM
     */
    @Trace(operationName = "D1获取公共字段入参(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ObtainCommonFieldRefComRespDto obtainCommonFieldRefCom(ObtainCommonFieldRefComReqDto reqDto) {


        QueryReceiveFieldDetailRespDto receptionServiceRes_1 = null;
        GenerateDataObjectBatchCodeComRespDto generateDataObjectBatchCodeComRespDto_1 = null;
        Organization organization_1 = null;
        QuerySpaceManagerDetailComRespDto querySpaceManagerDetailComRespDto_1 = null;
//步骤0: M1-获取接收字段（特殊方法） - queryReceiveFieldDetail
        //ModelCode: receptionService
        QueryReceiveFieldDetailRespDto receptionServiceRes = null;
        QueryReceiveFieldDetailReqDto receptionServiceReq = new QueryReceiveFieldDetailReqDto();
        receptionServiceReq.setCalcStartTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME//sourceId:1811446_1

        /*M1获取计算开始时间[3715]  用于特殊方法接收上游入参。 */
        Assert.isNull(receptionServiceReq.getCalcStartTime(), "D1获取公共字段入参(公共)-M1获取计算开始时间-计算开始时间不能为空", false);
        receptionServiceRes = nbDashboradStandardData.queryReceiveFieldDetail(receptionServiceReq);


        receptionServiceRes_1 = receptionServiceRes;

//步骤1: D2生成数据对象批次标识(公共) - generateDataObjectBatchCodeCom
        GenerateDataObjectBatchCodeComRespDto generateDataObjectBatchCodeComRespDto = null;
        GenerateDataObjectBatchCodeComReqDto generateDataObjectBatchCodeComReqDto = new GenerateDataObjectBatchCodeComReqDto();


        /*D2生成数据对象批次标识(公共)[9404]   */

        generateDataObjectBatchCodeComRespDto = interfaceModeService.generateDataObjectBatchCodeCom(generateDataObjectBatchCodeComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


        generateDataObjectBatchCodeComRespDto_1 = generateDataObjectBatchCodeComRespDto;

//步骤2: 1-3-12查询组织详情 - queryOrgDetail
        Organization organization = null;
        QueryOrgDetailReq queryOrgDetailReq = new QueryOrgDetailReq();
        queryOrgDetailReq.setIsHighOrg("TRUE");//sourceId:1670969_1
        queryOrgDetailReq.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:1670986_1
        if (reqDto != null) {
            queryOrgDetailReq.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1670970_1
        }

        /*1-3-12查询组织详情[201]   */
        Assert.isNull(queryOrgDetailReq.getIsHighOrg(), "D1获取公共字段入参(公共)-1-3-12查询组织详情-是否最高组织不能为空", false);
        Assert.isNull(queryOrgDetailReq.getSubjectLifeCycle(), "D1获取公共字段入参(公共)-1-3-12查询组织详情-主体生命周期不能为空", false);
        Assert.isNull(queryOrgDetailReq.getSpaceId(), "D1获取公共字段入参(公共)-1-3-12查询组织详情-创建于空间ID不能为空", false);
        organization = mOrganizationService.queryOrgDetail(queryOrgDetailReq)/*vcase invoke 本地 method 方法调用;*/;


        organization_1 = organization;

//步骤3: D1查询空间管理员(公共) - querySpaceManagerDetailCom
        QuerySpaceManagerDetailComRespDto querySpaceManagerDetailComRespDto = null;
        QuerySpaceManagerDetailComReqDto querySpaceManagerDetailComReqDto = new QuerySpaceManagerDetailComReqDto();
        if (reqDto != null) {
            querySpaceManagerDetailComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1671541_1
        }

        /*D1查询空间管理员(公共)[8945]   */
        Assert.isNull(querySpaceManagerDetailComReqDto.getSpaceId(), "D1获取公共字段入参(公共)-D1查询空间管理员(公共)-创建于空间ID不能为空", false);
        querySpaceManagerDetailComRespDto = roleService.querySpaceManagerDetailCom(querySpaceManagerDetailComReqDto)/*vcase invoke isSameApp*/;


        querySpaceManagerDetailComRespDto_1 = querySpaceManagerDetailComRespDto;

        ObtainCommonFieldRefComRespDto retData = new ObtainCommonFieldRefComRespDto();
        if (receptionServiceRes_1 != null) {
            retData.setCalcStartTime(receptionServiceRes_1.getCalcStartTime());//SimpleFieldAssign//sourceId:1811449_1
        }
        if (generateDataObjectBatchCodeComRespDto_1 != null) {
            retData.setDataObjectBatchCode(generateDataObjectBatchCodeComRespDto_1.getDataObjectBatchCode());//SimpleFieldAssign//sourceId:1811450_1
        }
        if (organization_1 != null) {
            retData.setOrganizationId(organization_1.getOrganizationId());//SimpleFieldAssign//sourceId:1670989_1
        }
        if (querySpaceManagerDetailComRespDto_1 != null) {
            retData.setInductionRecordId(querySpaceManagerDetailComRespDto_1.getInductionRecordId());//SimpleFieldAssign//sourceId:1671544_1
        }


        return retData;
    }
    //
}
